package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.api.net.SBApiService
import de.baumann.browser.api.net.WalletApiService
import de.baumann.browser.api.net.base.ApiBuilder
import de.baumann.browser.api.net.vo.OcTransfer
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IOcWalletView
import de.baumann.browser.rx.RxSchedulers

class OcWalletPresenter : BasePresenter<IOcWalletView>() {
    private val walletService: WalletApiService = ApiBuilder.buildService(WalletApiService::class.java)
    fun getTransferRecord() {
        walletService.getTransferRecord(view!!.getAddress(), view.getType(),view.getPageNum())
                .compose(RxSchedulers.ioMain())
                .subscribe(object : OdinObserver<List<OcTransfer>>(view) {
                    override fun onSuccess(data: List<OcTransfer>?) {
                        if (view != null && data != null) {
                            view.setTransfers(data)
                        }
                    }
                })
    }

    fun getTransferRecordOC(ct:String) {
        val sbApiService: SBApiService = ApiBuilder.buildService(SBApiService::class.java)
        sbApiService.getTransferRecord(view!!.getAddress(), view.getType(),ct)
                .compose(RxSchedulers.ioMain())
                .subscribe(object : OdinObserver<List<OcTransfer>>(view) {
                    override fun onSuccess(data: List<OcTransfer>?) {
                        if (view != null && data != null) {
                            view.setTransfers(data)
                        }
                    }
                })
    }

}